import React from 'react';
import { Link } from 'react-router';
import FormEditPatient from '../../components/formEditPatient';
import { connect } from 'react-redux'
import { changePage } from '../../store/actions';


class _PatientEdit extends React.Component{
    constructor(props){
        super(props);
        this.onSub = this.onSub.bind(this);
        this.state ={
            _id : this.props.params?this.props.params.id:false
        };
        this.changePage = this.changePage.bind(this)
    }
    onSub(v){
        this.props.onSub(v)
    }
    changePage(){
        this.props.dispatch(changePage('patient-detail'));
    }
    static contextTypes = {
        router: React.PropTypes.object
    };
    render(){
        return(
            <div id="image-add">
                <FormEditPatient
                    _id={this.props.params.id}
                    user={this.props.user}
                    dispatch={this.props.dispatch}
                    patients ={this.props.items}
                    _r = {this.context.router}
                    onSub={this.onSub}
                />
            </div>
        )
    }
}
const PatientEdit = connect((state) => {
    const {user} = state.rootReducer;
    const {items} = state.rootReducer.patients;
    const {pathname} = state.routing.locationBeforeTransitions;
    return {user,items,pathname}
})(_PatientEdit);
export default PatientEdit